﻿using System.Collections.Generic;
using System.Linq;
using Model;

namespace DAL
{
    public class CityContacts
    {
        public static IList<Model.ViewModel.CityContacts> SelectAll()
        {
            var cityContacts = DbHelper.Db.CityContacts.Include("City").ToList();
            return ClassConvert<Model.ViewModel.CityContacts, Model.CityContacts>.Convert(cityContacts);
        }


        public static void Add(Model.CityContacts contact)
        {
            DbHelper.Db.CityContacts.Add(contact);
            DbHelper.Db.SaveChanges();
        }

        public static void Update(Model.CityContacts newCityContact)
        {
            var cc = DbHelper.Db.CityContacts.Find(newCityContact.CityContactsId);
            cc.City = newCityContact.City;
            cc.Contacts = newCityContact.Contacts;
            DbHelper.Db.SaveChanges();
        }

        public static void Delete(int id)
        {
            var contact = DbHelper.Db.CityContacts.Find(id);
            DbHelper.Db.CityContacts.Remove(contact);
            DbHelper.Db.SaveChanges();
        }
        
    }
}